package com.gensdai.leliang.activity;


import android.os.Build;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.gensdai.leliang.R;
import com.gensdai.leliang.base.BaseActivityNoAbs;
import com.gensdai.leliang.remoteInterface.URLConfig;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/6/14.
 */

public class LoginDeal extends BaseActivityNoAbs implements View.OnClickListener {

    @BindView(R.id.ui_title)
    TextView uiTitle;
    @BindView(R.id.back)
    LinearLayout back;
    @BindView(R.id.webview)
    WebView webview;

    private String type = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.logindeal);
        ButterKnife.bind(this);
        init();
        setweb();

    }

    private void init() {
        // TODO Auto-generated method stub
//        type = getIntent().getStringExtra("type");
        uiTitle.setText(getIntent().getStringExtra("title"));
        type = getIntent().getStringExtra("type");

        back.setOnClickListener(this);

    }

    private void setweb() {
        // TODO Auto-generated method stub
        WebSettings settings = webview.getSettings();

        webview.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                return super.shouldOverrideUrlLoading(view, url);
//                System.out.println(url);
//                if (url.equals("http://test1.gensdai.com:8080/toLogin.do")
//                        || url.equals("https://www.gensdai.com/toLogin.do")) {
//                    user_help_in.this.finish();
//                } else {
//                    view.loadUrl(url);
//                }
//                return true;
            }
        });


//        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
//            settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.TEXT_AUTOSIZING);
//        } else {
//            settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
//        }

        settings.setJavaScriptCanOpenWindowsAutomatically(true);
        settings.setUseWideViewPort(true);// 关键点
        settings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        settings.setDisplayZoomControls(false);
        settings.setJavaScriptEnabled(true); // 设置支持javascript脚本
        settings.setAllowFileAccess(true); // 允许访问文件
        settings.setBuiltInZoomControls(true); // 设置显示缩放按钮
        settings.setSupportZoom(true); // 支持缩放
        settings.setUseWideViewPort(true);
        settings.setLoadWithOverviewMode(true);
        if (type.equals("1")) {
            webview.loadUrl(URLConfig.BASEDOMAIN + "group-introduction.jsp");
        } else {
            webview.loadUrl("https://www.lelong1788.com/off/agreement.jsp");
        }
    }

    @Override
    public void onClick(View v) {
        // TODO Auto-generated method stub

        switch (v.getId()) {
            case R.id.back:
                this.finish();
                break;

            default:
                break;
        }
    }

}
